// 更新表格
function updateTableBody(page)
{
   var str = "";
   var tpl_str = "<div class=\"row\"><div class=\"ttd_1\" id=\"name_#{id}\">#{username}</div>"
           + "<div class=\"ttd_2\" id=\"reg_time_#{id}\">#{register_time}</div>"
           + "<div class=\"ttd_3\" id=\"op_#{id}\"><select id=\"chsection_#{id}\" name=\"chsection_#{id}\" onchange=\"chSection(#{id});\">#{section_options}</select></div>"
           + "<div class=\"ttd_4\" id=\"status_#{id}\"></div></div>";
   var tpl = new Template(tpl_str);
   var hash_array = [];
   
   var url = "section_allocate.php";
   var pars = { "page_status": 1, "page": page };
   var myAjax = new Ajax.Request(
       url,
       {
	  method: "post",
	  parameters: pars,
	    onComplete: function(req) 
	      {
		 var xmlobj = req.responseXML;
		 var perpage = parseInt(xmlobj.getElementsByTagName("perpage")[0].childNodes[0].nodeValue, 10);
		 var wholepage = parseInt(xmlobj.getElementsByTagName("wholepage")[0].childNodes[0].nodeValue, 10);
		 var items = $A(xmlobj.getElementsByTagName("item"));
		 items.each(function(el) {
		    var h = {};
		    var item_id = el.getElementsByTagName("id")[0].childNodes[0].nodeValue;
		    var item_username = el.getElementsByTagName("username")[0].childNodes[0].nodeValue;
		    var item_register_time = el.getElementsByTagName("register_time")[0].childNodes[0].nodeValue;
		    var item_sec_options = el.getElementsByTagName("options")[0].childNodes[0].nodeValue;
		    h["id"] = item_id;
		    h["username"] = item_username;
		    h["register_time"] = item_register_time;
		    h["section_options"] = item_sec_options;
		    hash_array[hash_array.length] = h;
		 });
		 $A(hash_array).each(function(aitem) {
		    str += tpl.evaluate(aitem);
		 });
		 $("tbody").update(str);
	      }
       });
}

// 更改员工部门
function chSection(id)
{
   var url = "section_allocate.php";
   var pars = 
     {
	"id": id,
	"page_status": 2,
	  "section_id": $F("chsection_" + id)
     };
   var myAjax = new Ajax.Request(
       url,
       {
	  method: "post",
	    parameters: pars,
	    onComplete: function(req)
	      {
		 $("status_" + id).update((req.responseText.include("success")) ? "<font color=\"green\">更改员工部门成功！</font>" : "<font color=\"red\">更改员工部门失败！</font>");
	      }
       }
   );
}
